package com.example.oasystem.service.impl;

import com.example.oasystem.dao.notice.AoaUserNoticeDao;
import com.example.oasystem.entity.notice.AoaNoticeListOfSun;
import com.example.oasystem.entity.status.AoaStatusList;
import com.example.oasystem.entity.type.AoaTypeList;
import com.example.oasystem.entity.user.AoaUser;
import com.example.oasystem.service.AoaNoticeListService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AoaNoticeListServiceImpl implements AoaNoticeListService {

    @Autowired
    private AoaUserNoticeDao aoaUserNoticeDao;

    @Override
    public PageInfo<AoaNoticeListOfSun> selectNoticeAndUserAndTypeAndStatus(int pageNum, int pageSize, String baseKey, AoaUser aoauser) {
        PageHelper.startPage(pageNum,pageSize);
        System.out.println("baseKey = " + baseKey);
        System.out.println("aoauser = " + aoauser);
        List<AoaNoticeListOfSun> lists = aoaUserNoticeDao.selectNoticeAndUserAndTypeAndStatus(baseKey,aoauser);
        PageInfo<AoaNoticeListOfSun> pageInfo = new PageInfo<>(lists);
        return pageInfo;
    }



    @Override
    public List<AoaTypeList> selectNoticeType() {
        return aoaUserNoticeDao.selectNoticeType();
    }

    @Override
    public List<AoaStatusList> selectNoticeStatus() {
        return aoaUserNoticeDao.selectNoticeStatus();
    }

    @Override
    public AoaNoticeListOfSun selectONENoticeAll(int id) {
        return aoaUserNoticeDao.selectONENoticeAll(id);
    }

    @Override
    public void updateNotice(AoaNoticeListOfSun aoaNotice) {
        aoaUserNoticeDao.updateNotice(aoaNotice);
    }

    @Transactional
    @Override
    public void addNotice(AoaNoticeListOfSun aoaNotice, List<AoaUser> aoaUsers) {
        System.out.println("aoaNotice111111111111111 = " + aoaNotice);
        aoaUserNoticeDao.addNotice(aoaNotice);
        System.out.println("aoaNotice6666666666666666 = " + aoaNotice);
        long noticeId = aoaNotice.getNoticeId();
        aoaUserNoticeDao.insertRelation(aoaUsers,noticeId);
    }

    @Override
    public AoaNoticeListOfSun selectUserNotice(long id) {
        return aoaUserNoticeDao.selectUserNotice(id);
    }

    @Transactional
    @Override
    public void delectNotice(long id) {
        aoaUserNoticeDao.delectNoticeRelation(id);
        aoaUserNoticeDao.delectNotice(id);
    }

    @Override
    public void updateTop(int isTop, long noticeId) {
        aoaUserNoticeDao.updateTop(isTop,noticeId);
    }


}
